using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_LevelMapRegionItem : UIBaseNode
    {
        #region Template Generate,don't modify

        protected class UIB_UIN_LevelMapRegionItem
        {
            #region ObjectBinding Generate

            public ExText name { protected set; get; }
            public GameObject locationMark { protected set; get; }
            public GameObject targetMark { protected set; get; }
            public ExButton regionButton { protected set; get; }
            public ExImage selected { protected set; get; }

            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<ExText>("name", out var __tbv0);
                name = __tbv0;
                __binding.TryGetVariableValue<GameObject>("locationMark", out var __tbv1);
                locationMark = __tbv1;
                __binding.TryGetVariableValue<GameObject>("targetMark", out var __tbv2);
                targetMark = __tbv2;
                __binding.TryGetVariableValue<ExButton>("regionButton", out var __tbv3);
                regionButton = __tbv3;
                __binding.TryGetVariableValue<ExImage>("selected", out var __tbv4);
                selected = __tbv4;
            }

            #endregion ObjectBinding Generate
        }

        #endregion Template Generate,don't modify


        public static Action<int> onItemSelected;

        #region fields

        private int _regionCid;

        #endregion

        #region properties

        protected UIB_UIN_LevelMapRegionItem ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => _msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_LevelMapRegionItem();
            ui.InitBinding(csObjBind);
        }

        protected override void OnInit()
        {
            ui.locationMark.SetActive(false);
            ui.targetMark.SetActive(false);
            ui.regionButton.AddClickEvent(OnClick);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        public void Refresh(int regionCid)
        {
            _regionCid = regionCid;
            ui.name.text = TableCenter.regionInstance.Get(regionCid).Name;
            ui.locationMark.SetActive(regionCid == GameplayAreaManager.Instance.curSceneArea.curRegionCid);
        }

        public void UpdateSelect(int curSelectedRegionCid)
        {
            //ui.selected.indexSwitchSprite = curSelectedRegionCid == _regionCid ? 0 : 1;
        }

        protected override void OnDispose()
        {
        }

        #region methonds

        private void OnClick()
        {
            onItemSelected?.Invoke(_regionCid);
        }

        #endregion methonds
    }
}